/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ejb.controllers;

import java.io.Serializable;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import org.ejb.persistencia.Administrador;
import org.ejb.persistencia.Usuarios;

/**
 *
 * @author MoisesAntonio
 */
@Named
@SessionScoped

public class Login implements Serializable {


    @Inject Credentials credentials;
    @EJB
    private org.ejb.negocio.UsuariosFacade ejbFacade;
    //@EJB
    //private org.ejb.negocio.AdministradorFacade ejbFacade2;

    private Usuarios user;

    private Administrador admin;
    

    public void login() {
        //admin=ejbFacade2.login(credentials.getUsername(), credentials.getPassword());
        user=ejbFacade.login(credentials.getUsername(), credentials.getPassword());
        
    }

    

    public void logout() {

        admin = null;
        user = null;

    }
    
    public boolean isLoggedIn() {

       return user!=null || admin!=null;

    }

    @Produces @LoggedIn Usuarios getCurrentUser() {
        return user;
    }
    
    @Produces @LoggedIn Administrador getCurrentAdmin() {
        return admin;
    }


}
